package com.data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ConnData {

    Connection conn=null;
    Statement stmt=null;
    PreparedStatement psmt=null;
    ResultSet rs=null;

    public ConnData()
    {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        }
        catch(Exception e)
        {
            e.getMessage();
        }

    }

    public Connection getConn()
    {

        String url="jdbc:mysql://localhost:3306/pythonoj?serverTimezone=UTC";

        try {
            conn=DriverManager.getConnection(url,"root","123A123a123@");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return conn;
    }

    public PreparedStatement getPsmt(String sql)
    {
        try {
            psmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return psmt;
    }

    public void close()
    {
        try {
            if(psmt!=null)
                psmt.close();
            conn.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}
